#include <iostream>
#include <GLFW/glfw3.h>

// 通过LegacyOpenGL画一个三角形
void drawTRrangleWithlegacyOpenGL() {
    glBegin(GL_TRIANGLES);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f(0.0f, 0.5f);
    glVertex2f(0.5f, -0.5f);
    glEnd();
}

int main(void) {
    // 创建GLFW窗体
    GLFWwindow* window;
    if (!glfwInit()) return -1; // 初始化GLFW
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); // 初始化一个窗口并且获取它的OpenGL上下文
    if (!window) {
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window); // Make the window's context current

    // 重复渲染循环直到关闭了窗口 Render here
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);

        // 在这里进行OpenGL图形DrawCall
        drawTRrangleWithlegacyOpenGL();

        // Swap front and back buffers
        glfwSwapBuffers(window);

        // Poll for and process events
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}